<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <img src="https://www.runoob.com/wp-content/uploads/2016/02/ogimage.png" alt="" style="width: 60vw;height: 60vh;">
    <pre>
扩展：https://blog.csdn.net/gao_xu_520/article/details/125296635
    ：https://blog.csdn.net/chuan0106/article/details/119837508
</pre>
    <script src="./src/react.js"></script>
    <script src="./src/react-dom.js"></script>
    <script src="./src/babel.js"></script>

    <script type="text/babel">
        class Title extends React.Component {
            constructor() {
                super();
                this.state = {
                    n: 1
                }
                console.log("属性")
            }
            // componentWillMount(){
            //     console.log("组件将要挂载到视图")
            // }
            componentDidMount() {
                console.log("组件已经挂载到视图--执行一次")
            }
            componentDidUpdate() {
                console.log("组件已更新 -- state props 更新后 就会执行")
            }
            jia = () => {
                let n = this.state.n + 1
                this.setState({
                    n: n
                })
            }

            componentWillUnmount() {
                console.log("组件将要销毁-- 执行一次")
            }

            render() {
                console.log("render渲染函数 -- state props 更新后 就会执行")
                return (
                    <div>
                        头部组件 {this.state.n}
                        <button onClick={this.jia}>点击+1</button>

                    </div>
                )
            }
        }



        ReactDOM.render(
            <div>
                <Title ></Title>

            </div>,
            document.getElementById("app")
        )

    </script>

</body>

</html>